/*
 * @Author: your name
 * @Date: 2020-08-19 21:09:57
 * @LastEditTime: 2020-08-19 21:22:12
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \demo\day02\traning\test04\main.go
 */
package test04

// 第一层
type Builder interface {
	Build()
}

// 第二层
type Director struct {
	build Builder
}

// 第二层初始化
func NewDirector(b Builder) Director {
	return Director{build: b}
}

// 第二层实例方法
func (d *Director) Construct() {
	d.build.Build()
}

// 第三层
type ConstructBuilder struct {
	built bool
}

// 第三层初始化
func NewConstructBuilder() ConstructBuilder {
	return ConstructBuilder{}
}

// 第三层实例方法
func (b *ConstructBuilder) Build() {
	b.built = true
}

// 第四层
type Product struct {
	Built bool
}

// 使用第三层来初始化第四层
func (b *ConstructBuilder) GetResult() Product {
	return Product{Built: b.built}
}

// func main() {

// 	constructBuilder := NewConstructBuilder()
// 	director := NewDirector(&constructBuilder)
// 	director.Construct()
// 	result := constructBuilder.GetResult()
// 	fmt.Println(result.Built)
// }
